/*
* PCInt.c
*
* Created: 19.01.2014 17:11:10
*  Author: Hf
*/
#include <avr\interrupt.h>
#include <avr\sleep.h>
#include "defines.h"
#include "PCInt.h"
#include "asf.h"
#include "globals.h"
#include "OLED.h"

void init_PCInt(void){
	PCICR = _BV(PCIE2);		//enable PCInt16 to PCInt23
	PCMSK2 = 0b00011100;	//enable PCInt18/19/20
}

ISR(PCINT2_vect){
	shutdown_timer = 0;
	delay_ms(10);			//wait for debounce
	if(!(PINC & 0b00000100)){
		if (state == IDLE){
			state = MENU;
			menu_state = M_PREDIVE;
			new_state = 1;
			} else {
			key_down_flag = 1;
		}
	}
	if(!(PINC & 0b00001000)){
		if (state != IDLE){
			key_right_flag = 1;
		}
	}
	if(!(PINC & 0b00010000)){
		if (state != IDLE){
			key_left_flag = 1;
		}
	}
	PCIFR = 0b00000100;		//clear pin change interrupt flag 2
}